package view.test;

import java.awt.Component;
import java.awt.Point;
import java.awt.event.MouseEvent;

import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputListener;

import controller.GameController;
import controller.actions.EntityAction;
import controller.actions.EntityClickedAction;

public class EntityMouseInputListener implements MouseInputListener {
	
	private Point cell;
	private GameController controller;
	private GlassPane glassPane;
	
	public EntityMouseInputListener(Point cell, GameController controller, GlassPane glassPane) {
		this.cell = cell;
		this.controller = controller;
		this.glassPane = glassPane;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
		EntityClickedAction action = new EntityClickedAction(cell, e.getButton());
		controller.handleEntityClickedAction(action);

	}
	
	@Override
	public void mouseReleased(MouseEvent arg0) {
	}
	
	@Override
	public void mouseDragged(MouseEvent arg0) {
		
		Component component = arg0.getComponent();
		Point glassPanePoint = SwingUtilities.convertPoint(component, arg0.getPoint(), glassPane);
		glassPane.setCursorPoint(glassPanePoint);
		glassPane.repaint();
		
		EntityAction action = new EntityAction(cell);
		controller.handleEntityDraggedAction(action);
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {}
	@Override
	public void mouseExited(MouseEvent arg0) {}
	@Override
	public void mousePressed(MouseEvent arg0) {}
	@Override
	public void mouseMoved(MouseEvent arg0) {
		Component component = arg0.getComponent();
		Point glassPanePoint = SwingUtilities.convertPoint(component, arg0.getPoint(), glassPane);
		glassPane.setCursorPoint(glassPanePoint);
		glassPane.repaint();
	}

}
